﻿using System;
using System.Text;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using QzEbook.AccessObject;
using QzEbook.Common;
using System.IO;

public partial class module_ForOrBackWard : System.Web.UI.UserControl
{
    private StringBuilder sb;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }

    private void BindData()
    {

        int Bid = int.Parse(Request["Bid"]);
        DetaiBookView book = new DetaiBookView();
        book.BId = Bid;
        book = book.select();
        sb = new StringBuilder();
        sb.Append("<ul>");
        addBookRow("下一本杂志",book.selectForward(book.PostDate));

        addBookRow("上一本杂志", book.selectBackward(book.PostDate));
        sb.Append("</ul>");
    }

    private void addBookRow(string title,DetaiBookView book)
    {
        if (sb == null)
        {
            sb = new StringBuilder();
        }
        if (book == null)
        {
            return;
        }

        sb.AppendLine("<li class=\"subItem\">");
        sb.AppendFormat("<h3>{0}</h3>",title);
        sb.AppendFormat("<a href=\"detail.xhtml?Bid={0}\" title=\"{1}\">", book.BId, book.Title);
        if (book.Price > 0)
        {
            sb.AppendLine("<dfn class='auditing'><img src=\"images/siteIcon/auditing.gif\" alt='收费' /></dfn>");
        }

        string path = string.Format("{0}{1}", Config.UserBookSavePath, book.Path);
        if (!File.Exists(Server.MapPath(path)))
        {
            path = "images/siteIcon/error.gif";
        }
        sb.AppendFormat("<img src=\"{0}\" alt=\"view\" />", path);
        sb.AppendLine(" <ins>");
        sb.AppendFormat("<acronym>标题:{0}</acronym>", book.Title);
        sb.AppendLine("</ins>");
        sb.AppendLine(" </a></li>");
    }


    protected override void Render(HtmlTextWriter writer)
    {
        if (sb != null)
        {
            writer.Write(sb.ToString());
        }
        base.Render(writer);
    }
}
